<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据来源">
              <j-dict-select-tag placeholder="请选择单据来源" @input="handleDocumentSource" v-model="queryParam.permissionType" dictCode="permission_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 3">
            <a-form-item label="选择部门">
              <J-select-multiple
                placeholder="请选择选择部门"
                :options="getDepartName"
                showId="id"
                v-model="queryParam.deptIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 4">
            <a-form-item label="选择团队">
              <J-select-multiple
                placeholder="请选择选择团队"
                :options="getTeamName"
                showId="id"
                v-model="queryParam.teamIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="借阅申请编号" :labelCol="labelCol" class="form-item">
              <j-input placeholder="请输入借阅申请编号" v-model="queryParam.borrowApplyNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="签订公司" :labelCol="labelCol">
              <select-company-input v-model="queryParam.applyCompany" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同名称" :labelCol="labelCol" class="form-item">
              <j-input placeholder="请输入合同名称" v-model="queryParam.contractName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否外带" :labelCol="labelCol">
              <j-dict-select-tag placeholder="请选择是否外带" v-model="queryParam.takeout" dictCode="yes_no"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否归还" :labelCol="labelCol">
              <j-dict-select-tag placeholder="请选择是否归还" v-model="queryParam.giveBack" dictCode="yes_no"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="借阅日期" :labelCol="labelCol" class="form-item">
              <a-range-picker
                format="YYYY-MM-DD"
                :placeholder="['开始日期', '结束日期']"
                v-model="borrowDateRange"
                @change="(dates, dateStrs) => { queryParam.borrowDate_begin = dateStrs[0]; queryParam.borrowDate_end = dateStrs[1] }"
                style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="预计归还日期" :labelCol="labelCol" class="form-item">
              <a-range-picker
                format="YYYY-MM-DD"
                :placeholder="['开始日期', '结束日期']"
                v-model="predictReturnDateRange"
                @change="(dates, dateStrs) => { queryParam.predictReturnDate_begin = dateStrs[0]; queryParam.predictReturnDate_end = dateStrs[1] }"
                style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态" :labelCol="labelCol">
              <j-dict-select-tag placeholder="请选择审核状态" v-model="queryParam.bpmStatus" dictCode="bpm_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人" :labelCol="labelCol">
              <select-user-by-dep :multi="false" v-model="queryParam.proposer"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请部门" :labelCol="labelCol">
              <j-select-depart placeholder="请选择申请部门" v-model="queryParam.proposerDeptId"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="handleReset" icon="reload" style="margin-left: 8px;">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button
        @click="handleAddDiy"
        type="primary"
        icon="plus"
        :disabled="isDisabledAuth('erpOmcContractBorrowManager:add')">新增
      </a-button>
      <!-- 高级查询区域 -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcContractBorrowManager:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">
                      <ellipsis :length="15">{{item.title}}</ellipsis>
                    </a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, getCheckboxProps: (record) => { return { props: { disabled: record.bpmStatus !== '1' } } } }"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <span slot="notify" slot-scope="text, record">
          <a-icon
            title="催办提醒"
            v-if="record.taskUrge"
            theme="twoTone"
            twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode,record.id)"
            type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <template v-if="record.bpmStatus === '1'">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpOmcContractBorrowManager:edit')"/>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpOmcContractBorrowManager:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
          </template>
          <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
          </template>
          <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
              <a-button
                type="primary"
                size="small"
                :disabled="isDisabledAuth('erpOmcContractBorrowManager:invalidProcess')">
                作废流程
              </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
          </template>
          <template v-if="record.bpmStatus !== '1'">
            <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="handleTrack(record)" :disabled="isDisabledAuth('erpOmcContractBorrowManager:viewTrack')">审批进度</a-button>
          </template>
        </span>
        <a slot="borrowApplyNo" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
      </a-table>
    </div>
    <erp-omc-contract-borrow-manager-modal ref="modalForm" @ok="modalFormOk"></erp-omc-contract-borrow-manager-modal>
    <bpm-biz-task-deal-modal
      ref="taskDealModal"
      :path="path"
      :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    <process-config-modal ref="processConfig" @ok="handleSuccess" @close="handleClose"></process-config-modal>
  </a-card>
</template>
<script>
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpOmcContractBorrowManagerModal from './modules/ErpOmcContractBorrowManagerModal'
import { httpAction } from '@/api/manage'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
import Ellipsis from '@/components/Ellipsis'
export default {
  name: 'ErpOmcContractBorrowManagerList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcContractBorrowManagerModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectUserByDep,
    ProcessConfigModal,
    Ellipsis,
    SelectCompanyInput
  },
  data() {
    return {
      description: '合同借阅管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '借阅申请编号',
          align: 'center',
          dataIndex: 'borrowApplyNo',
          ellipsis: true,
          width: 154,
          scopedSlots: { customRender: 'borrowApplyNo' }
        },
        {
          title: '签订公司',
          align: 'center',
          dataIndex: 'applyCompany_dictText',
          ellipsis: true,
          width: 154,
        },
        {
          title: '是否外带',
          align: 'center',
          dataIndex: 'takeout_dictText',
          ellipsis: true,
          width: 154,
        },
        {
          title: '合同名称',
          align: 'center',
          dataIndex: 'contractName',
          ellipsis: true,
          width: 154,
        },
        {
          title: '是否归还',
          align: 'center',
          dataIndex: 'giveBack_dictText',
          ellipsis: true,
          width: 154,
        },
        {
          title: '借阅日期',
          align: 'center',
          dataIndex: 'borrowDate',
          ellipsis: true,
          width: 154,
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '预计归还日期',
          align: 'center',
          dataIndex: 'predictReturnDate',
          ellipsis: true,
          width: 154,
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '份数',
          align: 'center',
          dataIndex: 'borrowCount',
          ellipsis: true,
          width: 154,
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
          ellipsis: true,
          width: 154,
        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'proposerDeptId_dictText',
          ellipsis: true,
          width: 154,
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
          width: 154,
          scopedSlots: { customRender: 'bpmStatus' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 160,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/omc/contractmanager/erpOmcContractBorrowManager/list',
        delete: '/api/erp/omc/contractmanager/erpOmcContractBorrowManager/delete',
        deleteBatch: '/api/erp/omc/contractmanager/erpOmcContractBorrowManager/deleteBatch',
        exportXlsUrl: '/api/erp/omc/contractmanager/erpOmcContractBorrowManager/exportXls',
        importExcelUrl: 'api/erp/omc/contractmanager/erpOmcContractBorrowManager/importExcel',
        bizCount: '/api/erp/omc/contractmanager/erpOmcContractBorrowManager/bizCount',
        queryAddParameter: '/api/erp/omc/tenderfile/erpOmcTenderFile/queryAddParameter'
      },
      // 代码生成后需手动设置流程编码
      flowCode: 'dev_erp_omc_contract_borrow_manager_001',
      formUrl: 'erp/omc/contractmanager/modules/ErpOmcContractBorrowManagerForm',
      beanName: 'erpOmcContractBorrowManagerServiceImpl',
      formUrlMobile: '/pages/synergy/erpOmcContractBorrowManagerList',
      dictOptions: {},
      superFieldList: [],
      borrowDateRange: [],
      predictReturnDateRange: [],
      actualReturnDateRange: [],
      processId: ''
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    beginProcess(record){
      this.$refs.processConfig.visible = true
      this.$refs.processConfig.formUrl = this.formUrl
      this.$refs.processConfig.formUrlMobile = this.formUrlMobile
      this.$refs.processConfig.flowCode = this.flowCode
      this.$refs.processConfig.edit(record, this.processId, this.beanName)
    },
    handleSuccess(){
      this.loadData();
      this.$refs.modalForm.handleCancel()
      this.onClearSelected();
    },
    getDetail(id) {
      this.$router.push({
        path: `/erp/omc/contractmanager/ErpOmcContractBorrowManagerListDetail/${id}`,
      })
    },
    handleAddDiy() {
      let httpurl = '';
      let method = '';
      httpurl += this.url.queryAddParameter;
      method = 'POST';
      httpAction(httpurl, this.model, method).then((res) => {
        this.$nextTick(() => {
          this.$refs.modalForm.add(res.result);
          this.$refs.modalForm.title = '新增';
          this.$refs.modalForm.disableSubmit = false;
        })
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'borrowApplyNo', text: '借阅申请编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applyUser', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applyDept', text: '申请部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applyCompany', text: '签订公司', dictCode: '' })
      fieldList.push({ type: 'string', value: 'takeout', text: '是否外带', dictCode: 'yes_no' })
      fieldList.push({ type: 'string', value: 'contractName', text: '合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'giveBack', text: '是否归还', dictCode: 'yes_no' })
      fieldList.push({ type: 'date', value: 'borrowDate', text: '借阅日期' })
      fieldList.push({ type: 'date', value: 'predictReturnDate', text: '预计归还日期' })
      fieldList.push({ type: 'string', value: 'borrowCount', text: '份数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'borrowCause', text: '借阅事由', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applyUpload', text: '申请附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'hasReturned', text: '是否已归还', dictCode: 'yes_no' })
      fieldList.push({ type: 'date', value: 'actualReturnDate', text: '实际归还日期' })
      fieldList.push({ type: 'string', value: 'causeDescription', text: '说明原因', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleReset() {
      this.borrowDateRange = []
      this.predictReturnDateRange = []
      this.actualReturnDateRange = []
      this.searchReset()
      this.queryParam = {}
      this.loadData(1)
    }
  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
</style>
